<template>
    <div class="container">
        <el-card class="key-container" shadow="never">
            <div class="first-group">
                <span class="single-long-key"><span class="single-tip">A<sub class="single-bottom-number-tip">2</sub></span></span>
                <span class="single-first-short-key"></span>
                <span class="single-long-key"><span class="single-tip">B<sub class="single-bottom-number-tip">2</sub></span></span>
            </div>
            <div class="second-group">
                <span class="single-long-key"><span class="single-tip">C<sub class="single-bottom-number-tip">1</sub></span></span>
                <span class="single-first-short-key"></span>
                <span class="single-long-key"><span class="single-tip">D<sub class="single-bottom-number-tip">1</sub></span></span>
                <span class="single-second-short-key"></span>
                <span class="single-long-key"><span class="single-tip">E<sub class="single-bottom-number-tip">1</sub></span></span>
                <span class="single-long-key"><span class="single-tip">F<sub class="single-bottom-number-tip">1</sub></span></span>
                <span class="single-third-short-key"></span>
                <span class="single-long-key"><span class="single-tip">G<sub class="single-bottom-number-tip">1</sub></span></span>
                <span class="single-fourth-short-key"></span>
                <span class="single-long-key"><span class="single-tip">A<sub class="single-bottom-number-tip">1</sub></span></span>
                <span class="single-fifth-short-key"></span>
                <span class="single-long-key"><span class="single-tip">B<sub class="single-bottom-number-tip">1</sub></span></span>
            </div>
            <div class="third-group">
                <span class="single-long-key"><span class="single-tip">C</span></span>
                <span class="single-first-short-key"></span>
                <span class="single-long-key"><span class="single-tip">D</span></span>
                <span class="single-second-short-key"></span>
                <span class="single-long-key"><span class="single-tip">E</span></span>
                <span class="single-long-key"><span class="single-tip">F</span></span>
                <span class="single-third-short-key"></span>
                <span class="single-long-key"><span class="single-tip">G</span></span>
                <span class="single-fourth-short-key"></span>
                <span class="single-long-key"><span class="single-tip">A</span></span>
                <span class="single-fifth-short-key"></span>
                <span class="single-long-key"><span class="single-tip">B</span></span>
            </div>
            <div class="fourth-group">
                <span class="single-long-key"><span class="single-tip">c</span></span>
                <span class="single-first-short-key"></span>
                <span class="single-long-key"><span class="single-tip">d</span></span>
                <span class="single-second-short-key"></span>
                <span class="single-long-key"><span class="single-tip">e</span></span>
                <span class="single-long-key"><span class="single-tip">f</span></span>
                <span class="single-third-short-key"></span>
                <span class="single-long-key"><span class="single-tip">g</span></span>
                <span class="single-fourth-short-key"></span>
                <span class="single-long-key"><span class="single-tip">a</span></span>
                <span class="single-fifth-short-key"></span>
                <span class="single-long-key"><span class="single-tip">b</span></span>
            </div>
            <div class="fifth-group">
                <span class="single-long-key"><span class="single-tip">c<sup class="single-top-number-tip">1</sup></span></span>
                <span class="single-first-short-key"></span>
                <span class="single-long-key"><span class="single-tip">d<sup class="single-top-number-tip">1</sup></span></span>
                <span class="single-second-short-key"></span>
                <span class="single-long-key"><span class="single-tip">e<sup class="single-top-number-tip">1</sup></span></span>
                <span class="single-long-key"><span class="single-tip">f<sup class="single-top-number-tip">1</sup></span></span>
                <span class="single-third-short-key"></span>
                <span class="single-long-key"><span class="single-tip">g<sup class="single-top-number-tip">1</sup></span></span>
                <span class="single-fourth-short-key"></span>
                <span class="single-long-key"><span class="single-tip">a<sup class="single-top-number-tip">1</sup></span></span>
                <span class="single-fifth-short-key"></span>
                <span class="single-long-key"><span class="single-tip">b<sup class="single-top-number-tip">1</sup></span></span>
            </div>
            <div class="sixth-group">
                <span class="single-long-key"><span class="single-tip">c<sup class="single-top-number-tip">2</sup></span></span>
                <span class="single-first-short-key"></span>
                <span class="single-long-key"><span class="single-tip">d<sup class="single-top-number-tip">2</sup></span></span>
                <span class="single-second-short-key"></span>
                <span class="single-long-key"><span class="single-tip">e<sup class="single-top-number-tip">2</sup></span></span>
                <span class="single-long-key"><span class="single-tip">f<sup class="single-top-number-tip">2</sup></span></span>
                <span class="single-third-short-key"></span>
                <span class="single-long-key"><span class="single-tip">g<sup class="single-top-number-tip">2</sup></span></span>
                <span class="single-fourth-short-key"></span>
                <span class="single-long-key"><span class="single-tip">a<sup class="single-top-number-tip">2</sup></span></span>
                <span class="single-fifth-short-key"></span>
                <span class="single-long-key"><span class="single-tip">b<sup class="single-top-number-tip">2</sup></span></span>
            </div>
            <div class="seventh-group">
                <span class="single-long-key"><span class="single-tip">c<sup class="single-top-number-tip">3</sup></span></span>
                <span class="single-first-short-key"></span>
                <span class="single-long-key"><span class="single-tip">d<sup class="single-top-number-tip">3</sup></span></span>
                <span class="single-second-short-key"></span>
                <span class="single-long-key"><span class="single-tip">e<sup class="single-top-number-tip">3</sup></span></span>
                <span class="single-long-key"><span class="single-tip">f<sup class="single-top-number-tip">3</sup></span></span>
                <span class="single-third-short-key"></span>
                <span class="single-long-key"><span class="single-tip">g<sup class="single-top-number-tip">3</sup></span></span>
                <span class="single-fourth-short-key"></span>
                <span class="single-long-key"><span class="single-tip">a<sup class="single-top-number-tip">3</sup></span></span>
                <span class="single-fifth-short-key"></span>
                <span class="single-long-key"><span class="single-tip">b<sup class="single-top-number-tip">3</sup></span></span>
            </div>
            <div class="eighth-group">
                <span class="single-long-key"><span class="single-tip">c<sup class="single-top-number-tip">4</sup></span></span>
                <span class="single-first-short-key"></span>
                <span class="single-long-key"><span class="single-tip">d<sup class="single-top-number-tip">4</sup></span></span>
                <span class="single-second-short-key"></span>
                <span class="single-long-key"><span class="single-tip">e<sup class="single-top-number-tip">4</sup></span></span>
                <span class="single-long-key"><span class="single-tip">f<sup class="single-top-number-tip">4</sup></span></span>
                <span class="single-third-short-key"></span>
                <span class="single-long-key"><span class="single-tip">g<sup class="single-top-number-tip">4</sup></span></span>
                <span class="single-fourth-short-key"></span>
                <span class="single-long-key"><span class="single-tip">a<sup class="single-top-number-tip">4</sup></span></span>
                <span class="single-fifth-short-key"></span>
                <span class="single-long-key"><span class="single-tip">b<sup class="single-top-number-tip">4</sup></span></span>
            </div>
            <div class="ninth-group">
                <span class="single-long-key"><span class="single-tip">c<sup class="single-top-number-tip">5</sup></span></span>
            </div>
        </el-card>
    </div>
</template>

<script>
import { onBeforeMount, reactive } from "vue";
import { playLittleStar } from '@/utils/api';

export default {
    name: "Home",
    setup() {
        const data = reactive({
            
        });
        onBeforeMount(() => {
            document.addEventListener("keydown", playMusic);
            document.addEventListener("keyup", recover);
        });
        function playMusic(e) {
            const longKey = document.getElementsByClassName("single-long-key")[0];
            longKey.classList.add("active");
            playLittleStar();
        }
        function recover() {
            const longKey = document.getElementsByClassName("single-long-key")[0];
            longKey.classList.remove("active");
        }
        return {
            data,
        };
    },
};
</script>

<style scoped>
/* 总容器样式 */
.container {
    height: 100vh;
    position: relative;
    width: 100vw;
}

/* 琴键容器样式 */
.key-container {
    width: 100vw;
    text-align: center;
    position: absolute;
    bottom: 0;
    padding-bottom: 50px;
    left: 0;
    border: none;
}

/* 每一组的样式 */
.first-group,
.second-group,
.third-group,
.fourth-group,
.fifth-group,
.sixth-group,
.seventh-group,
.eighth-group,
.ninth-group {
    position: relative;
    display: inline-block;
}

/* 单个长琴键和短琴键的样式 */
.single-long-key {
    position: relative;
    width: 20px;
    height: 100px;
    background: white;
    border: 2px solid black;
    display: inline-block;
    margin-right: -2px;
}
.single-first-short-key {
    position: absolute;
    top: 0;
    left: 14px;
    width: 10px;
    height: 55px;
    background: black;
    display: block;
    z-index: 10;
}
.single-second-short-key {
    position: absolute;
    top: 0;
    left: 32px;
    width: 10px;
    height: 55px;
    background: black;
    display: block;
    z-index: 10;
}
.single-third-short-key {
    position: absolute;
    top: 0;
    left: 68px;
    width: 10px;
    height: 55px;
    background: black;
    display: block;
    z-index: 10;
}
.single-fourth-short-key {
    position: absolute;
    top: 0;
    left: 86px;
    width: 10px;
    height: 55px;
    background: black;
    display: block;
    z-index: 10;
}
.single-fifth-short-key {
    position: absolute;
    top: 0;
    left: 104px;
    width: 10px;
    height: 55px;
    background: black;
    display: block;
    z-index: 10;
}

/* 琴键激活样式 */
.active {
    background-color: #c881ab;
}

/* 琴键文字样式 */
.single-tip {
    position: absolute;
    top: 100px;
    left: 0;
    width: 100%;
    height: 30px;
    line-height: 30px;
    text-align: center;
    font-size: 12px;
    transform: scale(0.8);
}
.single-bottom-number-tip {
    transform: scale(0.8);
    position: absolute;
    top: 6px;
}
.single-top-number-tip {
    transform: scale(0.8);
    position: absolute;
    top: -6px;
}
</style>